package service

import (
	"context"
	"gitee.com/bei_yi_ning/gorder/stock/infra/integration"
	"gitee.com/bei_yi_ning/gorder/stock/infra/persistent"
	"github.com/spf13/viper"

	"gitee.com/bei_yi_ning/gorder/common/metrics"
	"gitee.com/bei_yi_ning/gorder/stock/adapters"
	"gitee.com/bei_yi_ning/gorder/stock/app"
	"gitee.com/bei_yi_ning/gorder/stock/app/query"
	"github.com/sirupsen/logrus"
)

func NewApplication(ctx context.Context) app.Application {
	stripeAPI := integration.NewStripeAPI()
	//stockRepo := adapters.NewMemoryStockRepository()
	stockRepo := adapters.NewMySQLStockRepository(persistent.NewMySQL())
	//metricsClient := metrics.TodoMetrics{}
	metricClient := metrics.NewPrometheusMetricsClient(&metrics.PrometheusMetricsClientConfig{
		Host:        viper.GetString("stock.metrics_export_addr"),
		ServiceName: viper.GetString("stock.service-name"),
	})
	return app.Application{Commands: app.Commands{}, Queries: app.Queries{
		CheckIfItemsInStock: query.NewCheckIfItemsInStockHandler(stockRepo, stripeAPI, logrus.StandardLogger(), metricClient),
		GetItems:            query.NewGetItemsHandler(stockRepo, logrus.StandardLogger(), metricClient),
	}}
}
